package com.zg.nacos.web;


import com.zg.common.core.R;

import com.zg.nacos.domain.convert.MicroNacosConvert;
import com.zg.nacos.domain.convert.MicroUserConvert;
import com.zg.nacos.domain.entity.MicroUser;
import com.zg.nacos.domain.req.MicroUserAddReq;
import com.zg.nacos.domain.vo.MicroUserVo;
import com.zg.nacos.service.MicroUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;


/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/6/16 20:23
 */

@RestController
@RequiredArgsConstructor
@RequestMapping("/micro/user")
@Slf4j
@Api(tags = "微服务用户")
public class MicroUserController {

    private final MicroUserService microUserService;

    private final MicroUserConvert microUserConvert;



    @PostMapping("/add")
    @ApiOperation(value = "新增用户")
    public R add(@Validated @RequestBody MicroUserAddReq addReq) {
        microUserService.add(addReq);
        return R.success();
    }


    @GetMapping("/getByUsername/{username}")
    public R<MicroUserVo> getByUsername(@PathVariable String username) {
        MicroUser vo=microUserService.getByUsername(username);
        return R.success(microUserConvert.toVo(vo));
    }
    //TODO
    @GetMapping("/list")
    public R<List<MicroUserVo>> getByUserId() {
        List<MicroUser> vo=microUserService.list();
        return R.success(microUserConvert.toVoList(vo));
    }

}
